package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping( "/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @GetMapping
    public Result getActivityList( ActivityDto activityDto){
        log.info("查询参数:{}",activityDto);
        PageResult<Activity> pageResult= activityService.getActivityList(activityDto);
        return Result.success(pageResult);
    }
    @DeleteMapping ("/{id}" )
    public Result deleteActivity(@PathVariable("id") Integer id){
        log.info("删除活动:{}",id);
        activityService.deleteActivity(id);
        return Result.success();
    }
    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        log.info("添加活动:{}",activity);
        activityService.addActivity(activity);
        return Result.success();
    }
    @GetMapping ("/{id}" )
    public Result getActivityById(@PathVariable("id") Integer id){
        log.info("查询活动:{}",id);
        return Result.success(activityService.getActivityById(id));
    }
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        log.info("修改活动:{}",activity);
        activityService.updateActivity(activity);
        return Result.success();
    }
    @GetMapping("/list")
    public Result getAll(){
        log.info("查询所有活动");
        return Result.success(activityService.getAll());
    }
    @GetMapping("//type/{type}")
    public Result getActivityByType(@PathVariable("type") Integer type){
        log.info("根据活动类型查询活动:{}",type);
        return Result.success(activityService.getActivityByType(type));
    }
}
